package com.zbl.zblproject.erp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zbl.zblproject.erp.entity.ErpWarehouse;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/10/10
 */
@Repository
public interface ErpWarehouseMapper extends BaseMapper<ErpWarehouse> {


    /**
     * 分页功能
     *
     * @param page
     * @param search 查询条件
     * @return
     */
    IPage<ErpWarehouse> selectPage(Page page, @Param("search") String search);

    IPage<ErpWarehouse> selectPageGroup(Page page, @Param("search") String search);

    IPage<ErpWarehouse> selectPageGroupNull(Page page, @Param("search") String search);

    IPage<ErpWarehouse> selectPageGroupNotNull(Page page, @Param("search") String search);

    List<ErpWarehouse> selectListByWarehouse(@Param("whName") String whName);

    /**
     * 查询所有的仓库名称
     *
     * @param status
     * @return
     */
    List<String> selectHouseName(int status);

    /**
     * 根据仓库名称和状态查询架位
     *
     * @param name
     * @param status
     * @return
     */
    List<String> selectShelves(@Param("name") String name, @Param("status") int status);


    /**
     * @param search
     * @return
     */
    List<ErpWarehouse> selectListOfSearch(@Param("search") String search);

    /**
     * @return
     */
    ErpWarehouse selectListOfSearchs(@Param("whId") int whId);

    @Select("select CONCAT(wh_name,'-',shelves_id,'-',goods_allocation) from zbl_erp_warehouse where id=6296")
    String selectPs();

    ErpWarehouse selectDefaultWarehouseByGoodsId(int goodsId);

    @Select("SELECT COUNT(*) FROM zbl_erp_warehouse_item WHERE stock != 0 AND goods_id != #{goodsId} AND wh_id = #{whId}")
    int foundGoodsCountInWarehouse(@Param("goodsId") int goodsId, @Param("whId") int whId);

    @Select("SELECT stock FROM zbl_erp_warehouse_item WHERE goods_id = #{goodsId} AND wh_id = #{whId}")
    Integer foundStockInWarehouse(@Param("goodsId") int goodsId, @Param("whId") int whId);
}
